<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="org.swim.web.utils.*"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="org.apache.commons.lang.WordUtils"%>
<%@page import="org.swim.remote.entities.IUser"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>

<!DOCTYPE html>
<html lang="en">
<head>
<%@include file="include/header.jsp"%>
<style type="text/css">
/* 	Collaboration */
.user-item {
	padding: 15px;
	padding-top: 10px;
	margin: 15px;
}

.user-item .alert {
	padding-right: 14px;
}

.user-item:HOVER {
	background: #eee;
}

.btn.disabled {
	opacity: 1;
}
</style>

<%
	JSONObject jsonSearch = (JSONObject) request.getAttribute("search");
	String what = jsonSearch.getString(SearchAttr.WHAT);
%>

<title><%=SwimConst.getTitle(WordUtils.capitalize(what
					.toLowerCase()) + " research")%></title>
</head>
<body>
	<%@include file="include/navbar.jsp"%>
	<%@include file="include/error-handling.jsp"%>
	<%@include file="include/new-collaboration.jsp"%>

	<div class="container">
		<div class="row">
			<div class="span8 ui-corner-all" style="background: #DDD">
				<div class="row">
					<div class="span8">
						<div style="margin: 20px;">
							<h5>
								<%
									if (jsonSearch.containsKey(SearchAttr.ABILITIES)) {
										JSONArray abilities = jsonSearch
												.getJSONArray(SearchAttr.ABILITIES);
										if (jsonSearch.getString(SearchAttr.QUERY) != null
												&& !jsonSearch.getString(SearchAttr.QUERY).equals(""))
											abilities.add(jsonSearch.getString(SearchAttr.QUERY));

										String abilitiesList = abilities.getString(0);
										for (int i = 1; i < abilities.size() - 1; i++) {
											abilitiesList += ", " + abilities.getString(i);
										}
										if (abilities.size() > 1)
											abilitiesList += " and "
													+ abilities.getString(abilities.size() - 1);
								%>
								Results for abilities
								<%=abilitiesList%>
								<%
									} else {
								%>
								Results for "<%=jsonSearch.getString(SearchAttr.QUERY)%>"
								<%
									}

									if (((List) request.getAttribute("friends")).size()
											+ ((List) request.getAttribute("nofriends")).size() == 0) {
								%>
								<br /> No result.
								<%
									}
								%>
							</h5>
						</div>

						<%
							if (SwimUtils.isLogged(request)) {
								List<IUser> friends = (List<IUser>) request
										.getAttribute("friends");
								for (int i = 0; i < friends.size(); i++) {
									request.setAttribute("user", friends.get(i));
						%>
						<%@include file="include/search-item.jsp"%>
						<%
							}
							}
						%>

						<%
							List<IUser> nofriends = (List<IUser>) request
									.getAttribute("nofriends");
							for (int i = 0; i < nofriends.size(); i++) {
								request.setAttribute("user", nofriends.get(i));
						%>
						<%@include file="include/search-item.jsp"%>
						<%
							}
						%>

					</div>
				</div>
			</div>
			<%@include file="include/notifications.jsp"%>
		</div>
	</div>
	<%@include file="include/footer.jsp"%>
	<%@include file="include/script-common.jsp"%>
</body>
</html>